// 时间戳 => YYYY-MM-DD hh:mm:ss
const getTime = function(data):String {
  const time = new Date(data)

  function timeAdd0(str) {
    if (str < 10) {
      str = '0' + str
    }
    return str
  }
  const y = time.getFullYear()
  const m = time.getMonth() + 1
  const d = time.getDate()
  const h = time.getHours()
  const mm = time.getMinutes()
  const s = time.getSeconds()
  const hms = timeAdd0(h) + ':' + timeAdd0(mm) + ':' + timeAdd0(s)

  const today = new Date()
  if (y === today.getFullYear() && m === today.getMonth() + 1) {
    if (d === today.getDate()) return hms
    if (d === today.getDate() - 1) return '昨天 ' + hms
  }

  return y + '-' + timeAdd0(m) + '-' + timeAdd0(d);
}


const getCurrentTime = function() {
  const time = new Date()
  return time.getTime()
}

export {getCurrentTime, getTime}